﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 改变角色状态的动作
/// </summary>
[CreateAssetMenu(menuName = "MyScript/Act/ControllableAct/Chracter1Act/ChangeStateAct")]
public class ChangeStateAct : ControllableAct
{
    [SerializeField] private ControllableObjectState m_toChangeState;

    [SerializeField] private GameTypeDefine.BUTTON_ID[] m_enterButton = { GameTypeDefine.BUTTON_ID.NONE };

    [SerializeField] private float m_pressedTime = -1;

    public override ControllableObjectState Act(ButtonEventArgs args, GameObject gameObject, ControllableObjectState state)
    {
        if (null == m_toChangeState)
        {
            m_toChangeState = ControllableStateMachine.previousState;
        }

        if (!state.isAtTop)
        {
            return ControllableStateMachine.remainState;
        }

        for (int i = 0, length = m_enterButton.Length; i < length; i++)
        {
            if (m_enterButton[i] == args.GetButtonID() && m_pressedTime < args.PressedTime)
            {
                return m_toChangeState;
            }
        }

        return base.Act(args, gameObject, state);
    }
}
